package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.SysLogMapper;
import com.itheima.service.SysLogService;
import com.itheima.pojo.SysLog;
import com.itheima.pojo.SysLogVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;


    /**
     * 展示操作日志列表
     * @param sysLogVO
     * @return
     */
    @Override
    public PageInfo getLogList(SysLogVO sysLogVO) {

        PageHelper.startPage(sysLogVO.getCurrentPage(),10);
        Example example = new Example(SysLog.class);

        Example.Criteria criteria = example.createCriteria();

        /*
        * 封装查询条件*/

        if(sysLogVO.getUserName()!=null&&!"".equals(sysLogVO.getUserName())){
            criteria.andEqualTo("userName",sysLogVO.getUserName());
        }
        if(sysLogVO.getOperation()!=null&&!"".equals(sysLogVO.getOperation())){
            criteria.andEqualTo("url",sysLogVO.getOperation());
        }
        List<SysLog> sysLogList = sysLogMapper.selectByExample(example);

        return new PageInfo<>(sysLogList);
    }
}
